package at.ac.lbg.media.vis.client.theme.manager
{
	import at.ac.lbg.media.vis.client.theme.view.Artwork;
	import at.ac.lbg.media.vis.client.theme.view.ArtworkDetail;
	
	import flare.vis.events.SelectionEvent;
	
	import mx.containers.VBox;
	import mx.core.Application;
	import mx.rpc.events.ResultEvent;
		
	public class DetailsManager {
		
		private var aw:Artwork;
		
		public function showDetails(evt:ResultEvent):void {
			
			var details:VBox = Application.application.details;
			var adObj:Object = Application.application.srv.getArtworkDetails.lastResult;
			var ad:ArtworkDetail = new ArtworkDetail(adObj);
//			var imgPath:String = "http://localhost:8080/images/";
			var imgPath:String = "http://vis.mediaartresearch.at:8080/visuframework/images/";

			Application.application.dtitle.htmlText = "<b>" + ad.title + "</b> "+ ad.year +"<br><i>" + ad.authors + "</i>";
			Application.application.dintro.htmlText = ad.introductionE;
			if (ad.imgFileName != null && ad.imgFileName.length > 3) {
				Application.application.dimg.source = imgPath + ad.imgFileName;
				Application.application.dimg.visible = true;
			} else {
				Application.application.dimg.visible = false;	
			}	
			
			//dispaly inside flareviz
			var a = Application.application;
			if (a.flareviz.mouseY > a.varFlarevizHeight - a.details.height){
				a.details.y = (a.details.height - 20) * -1;
			}else if (a.flareviz.mouseY < a.varFlarevizHeight - a.details.height){
				a.details.y = -10;
			}
			//TODO
			//jumps when first one is selected
			if (a.flareviz.mouseX > a.varFlarevizWidth - a.details.width){
				a.details.x = -a.details.width - 20;
			}else if (a.flareviz.mouseX < a.varFlarevizWidth - a.details.width){
				a.details.x = 15;
			}
			
			aw.addChild(details);
			details.invalidateSize();
			details.invalidateDisplayList();
			
			
			
			details.visible = true;			
//			for each (var cat:Category in ad.categories) {
//				for each (var activeCat:Category in Application.application.catFlatStructure) {
//					if (cat.id == activeCat.id) {
//						Application.application.details.data += cat.name + "\n";
//					}
//				}
//			}
		}
		
		public function onSingleClick(e:SelectionEvent):void{
			aw = e.item as Artwork;
			Application.application.srv.getArtworkDetails(aw.id);
			
		}
		
			
		public function onSecondClick(evt:ResultEvent):void {
//			landscape manager roll out
			Application.application.details.enabled = false;
			Application.application.details.visible = false;
			
		}

	}

}